package q1.project.modules.system.role.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import q1.project.common.enums.EnableStatusEnum;
import q1.project.core.entity.BaseEntity;
import q1.project.core.jpa.annotation.Comment;
import q1.project.modules.system.role.common.MenuTypeEnum;

/**
 * 菜单实体
 *
 * @author Q1 Team
 * @version 1.0
 */
@Getter
@Setter
@Entity
@Table(
    name = "q1_menu",
    indexes = {
      @Index(name = "idx_menu_code", columnList = "menu_code"),
      @Index(name = "idx_parent_id", columnList = "parent_id")
    })
public class MenuEntity extends BaseEntity {

  /** 父菜单ID（null表示顶级菜单） */
  @Comment("父菜单ID")
  @Column(name = "parent_id", length = 32)
  private String parentId;

  /** 父菜单名称 */
  @Comment("父菜单名称")
  @Column(name = "parent_name", length = 100)
  private String parentName;

  /** ID链路（用于快速查询菜单树，格式：menu_001_menu_002_menu_003） */
  @Comment("ID链路")
  @Column(name = "id_link", columnDefinition = "TEXT")
  private String idLink;

  /** 层级（从1开始） */
  @Comment("层级")
  @Column(name = "level", length = 2)
  private Integer level;

  /** 层级中文信息（如：一级菜单、二级菜单） */
  @Comment("层级中文信息")
  @Transient
  private String levelMsg;

  /** 菜单编码（唯一） */
  @Comment("菜单编码")
  @NotBlank(message = "菜单编码不能为空")
  @Column(name = "menu_code", nullable = false, length = 100)
  private String menuCode;

  /** 菜单名称 */
  @Comment("菜单名称")
  @NotBlank(message = "菜单名称不能为空")
  @Column(name = "menu_name", nullable = false, length = 100)
  private String menuName;

  /** 菜单类型：DIRECTORY-目录，MENU-菜单，BUTTON-按钮 */
  @Comment("菜单类型")
  @NotNull(message = "菜单类型不能为空")
  @Enumerated(EnumType.STRING)
  @Column(name = "menu_type", nullable = false, length = 20)
  private MenuTypeEnum menuType = MenuTypeEnum.DIRECTORY;

  /** 路由路径 */
  @Comment("路由路径")
  @Column(name = "path", length = 200)
  private String path;

  /** 组件路径 */
  @Comment("组件路径")
  @Column(name = "component", length = 200)
  private String component;

  /** 图标 */
  @Comment("图标")
  @Column(name = "icon", length = 50)
  private String icon;

  /** 排序号 */
  @Comment("排序号")
  @Column(name = "sort_order")
  private Integer sortOrder = 0;

  /** 备注 */
  @Comment("备注")
  @Column(name = "remark", length = 500)
  private String remark;

  /** 状态：ACTIVE-激活, DISABLED-禁用 */
  @Comment("状态")
  @Enumerated(EnumType.STRING)
  @Column(nullable = false, length = 20)
  private EnableStatusEnum status = EnableStatusEnum.ACTIVE;
}
